import 'package:flutter/cupertino.dart';
import 'package:jetour_line/base_widget/base_image.dart';
import 'package:jetour_line/base_widget/sliver_list_widget.dart';
import 'package:jetour_line/utils/extension_int.dart';

import '../../../model/line_detail_model.dart';
import '../../../my_colors.dart';

class LineDetailBudgetWidget extends StatefulWidget {
  final LineDetailModel lineDetailModel;

  const LineDetailBudgetWidget({Key? key, required this.lineDetailModel})
      : super(key: key);

  @override
  State<LineDetailBudgetWidget> createState() => _LineDetailBudgetWidgetState();
}

class _LineDetailBudgetWidgetState extends State<LineDetailBudgetWidget> {
  int? count = 0;

  @override
  Widget build(BuildContext context) {
    count = widget.lineDetailModel.lineData?.length;
    print('countcountcountcount = $count');
    // if (count! > 0) {
    //   count = (count! + 1)!;
    // }
    return SliverListWidget.getSliverList(count!+1, (context, index) {
      return Padding(padding:EdgeInsets.only(left: 24.px,right: 24.px),child:  groupWidget(index),);
    });
  }

  Widget groupWidget(int index) {
    if (index == count! ) {
      return totalWidget();
    }
    LineDatum? datum = widget.lineDetailModel.lineData![index];
    String day = 'DAY${index + 1}';
    String price = '¥${datum?.totalFee}';
    int? buLen = datum?.budget!.length;
    return Column(
      children: [
        Row(
          children: [
            SizedBox(
              height: 94.px,
            ),
            Expanded(
              child: Text(
                day,
                style: TextStyle(
                    fontSize: 30.px,
                    color: MyColors.color333333,
                    fontWeight: FontWeight.w500),
              ),
            ),
            Text(
              price,
              style: TextStyle(
                  fontSize: 30.px,
                  color: MyColors.color333333,
                  fontWeight: FontWeight.w500),
            ),
          ],
        ),
        for(int i = 0;i<buLen!;i++)
          childWidet(datum?.budget![i]),
        Container(
          width: double.infinity,
          height: 1.px,
          color: MyColors.colorE8ECF2,
        )
      ],
    );
  }

  Widget childWidet(Budget? budget) {
    String? type = budget?.typeName;
    List<BudgetNode?>? node = budget?.node;
    int? len = node?.length;
    bool showType = true;
    Color? typeColor;
    if(type == '景点'){
      typeColor = MyColors.color7BAB12;
    }else if(type == '餐饮'){
      typeColor = MyColors.colorE49B17;
    }else{
      typeColor = MyColors.color34BAA4;
    }
    return  Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        showType
            ? ClipRRect(
            borderRadius: BorderRadius.all(Radius.circular(6.px)),
            child: Container(
              alignment: Alignment.center,
              color: typeColor,
              width: 56.px,
              height: 32.px,
              child: Text(
                type!,
                style: TextStyle(fontSize: 20.px, color: MyColors.white),
              ),
            ))
            : SizedBox(
          width: 56.px,
        ),
        SizedBox(width: 16.px,),
        Expanded(child: Column(children: [
          for(int i = 0;i<len!;i++)
            nodeWidget(node![i])
        ],)),


      ],
    );
  }
  Widget nodeWidget( BudgetNode? node){
    String? caption = node!.caption;
    String? fee = '${node.fee!}';
    return  Padding(padding: EdgeInsets.only(bottom: 40.px),child: Row(children: [
      Expanded(
        child: Text(
          caption!,
          style: TextStyle(fontSize: 30.px, color: MyColors.color666666),
        ),
      ),
      SizedBox(
        height: 32.px,
        width: 10.px,
      ),
      Text(
        '￥$fee',
        style: TextStyle(fontSize: 30.px, color: MyColors.color666666),
      ),
    ],),);
  }

  Widget totalWidget() {
    String price = '¥${widget.lineDetailModel.totalFee}';
    String otherPrice = '¥${widget.lineDetailModel.otherFee}';
    return Column(children: [
      SizedBox(height: 16.px,),
      Row(
        children: [
          SizedBox(
            height: 94.px,
          ),
          Text(
            "总计",
            style: TextStyle(
                fontSize: 30.px,
              color: MyColors.color333333,
              fontWeight: FontWeight.w500
                ),
          ),
          Expanded(
            child: Text(
              "（单人单车）",
              style: TextStyle(
                  fontSize: 26.px,
                  color: MyColors.color999999,
                  fontWeight: FontWeight.w500
                  ),
            ),
          ),

          Text(
            price,
            style: TextStyle(
                fontSize: 30.px,
                color: MyColors.color333333,
                fontWeight: FontWeight.w500),
          ),
        ],
      ),
      Row(
        children: [
          SizedBox(height: 72.px,),
          BaseImage(image: 'ls_icon_price',width: 40.px,height: 40.px,),
          Text(
            "其他参考费用：过路费+油费=$otherPrice",
            style: TextStyle(
              fontSize: 26.px,
              color: MyColors.color999999, ),
          ),
        ],
      )
    ],);
  }
}
